package solitaire.presentation;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Stack;

import javax.swing.JFrame;
import javax.swing.JPanel;

import solitaire.controle.CTasDeCartes;

public class PTasDeCartes extends JPanel {

	private static final long serialVersionUID = 1L;

	private CTasDeCartes controle;
	private String display = "vertical";
	private Stack<PCarte> cartes;
	
	int nbCartes = 0;

	public PTasDeCartes(CTasDeCartes controle) {
		this.controle = controle;
		setLayout(null);
		setOpaque(false);

		setSize(PCarte.largeur, PCarte.hauteur);
		setPreferredSize(getSize());

		setBorder(null);
	}
	
	public void setVertical() {
		display = "vertical";
	}

	public void setHorizontal() {
		display = "horizontal";
	}

	public void setFlat() {
		display = "flat";
	}

	public void depiler(PCarte carte) {
	}

	public void empiler(PCarte carte) {
		nbCartes++;
		//cartes.push(carte);
		add(carte, 0);
				
		if (display == "vertical") {
			setSize(PCarte.largeur, PCarte.hauteur + nbCartes * 15);
			carte.setLocation(0, (nbCartes - 1) * 15);
		} else if (display == "horizontal") {
			setSize(PCarte.largeur * 2, PCarte.hauteur);
			carte.setLocation((nbCartes - 1) * 3, 0);
		} else if (display == "flat") {
			carte.setLocation((nbCartes - 1), 0);
		}
		
		setPreferredSize(getSize());
		setVisible(true);
	}

	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(Color.orange);
		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
	}

	public static void main(String args[]) {
		PCarte.initDimensions();
		
		JFrame f = new JFrame("Test PTasDeCartes");
		PTasDeCartes tas = new PTasDeCartes(null);
		f.getContentPane().add(tas);
		
		PCarte c1 = new PCarte("1C", null);
		PCarte c2 = new PCarte("1C", null);
		PCarte c3 = new PCarte("1C", null);
		
		tas.empiler(c1);
		tas.empiler(c2);
		tas.empiler(c3);
		
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.pack();
		f.setVisible(true);
	}
}